#ifndef _AMERICO_PLANE_VOLUME_H_
#define _AMERICO_PLANE_VOLUME_H_

#include <vector>
#include "Plane.h"

template <typename TYPE>
class PlaneVolume
{
private:
    std::vector< Plane<TYPE> > myPlaneList;

public:
    PlaneVolume();
    PlaneVolume(std::vector< Plane<TYPE> > aPlaneList);
    void AddPlane(const Plane<TYPE> &aPlane);
    void RemovePlane(const Plane<TYPE> &aPlane);
    bool Inside(const Vector3<TYPE> &aPosition) const;

	inline Plane<TYPE> &operator[](const unsigned int &anIndex) { return myPlaneList[anIndex]; }
	inline const Plane<TYPE> &operator[](const unsigned int &anIndex) const { return myPlaneList[anIndex]; }

	inline unsigned int size() const { return myPlaneList.size(); }
};

template <typename TYPE>
PlaneVolume<TYPE>::PlaneVolume()
{
}

template <typename TYPE>
PlaneVolume<TYPE>::PlaneVolume(std::vector< Plane<TYPE> > aPlaneList)
{
    myPlaneList = aPlaneList;
}

template <typename TYPE>
void PlaneVolume<TYPE>::AddPlane(const Plane<TYPE> &aPlane)
{
    myPlaneList.push_back(aPlane);
}

template <typename TYPE>
void PlaneVolume<TYPE>::RemovePlane(const Plane<TYPE> &aPlane)
{
    for(unsigned int index=0; index<myPlaneList.size(); ++index)
    {
        if(myPlaneList[index] == aPlane)
        {
            myPlaneList.erase(myPlaneList.begin()+index);
            return;
        }
    }
}

template <typename TYPE>
bool PlaneVolume<TYPE>::Inside(const Vector3<TYPE> &aPosition) const
{
    for(unsigned int index=0; index<myPlaneList.size(); ++index)
    {
        if(myPlaneList[index].Inside(aPosition) == false)
        {
            return false;
        }
    }
    return true;
}

#endif
